package com.bjut.dailyserver.controller;

import com.bjut.dailyserver.dao.UserDao;
import com.bjut.dailyserver.entity.TUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class TUserController {
    // 从spring容器中取得对象
    @Autowired
    UserDao userDao;
    @RequestMapping("/login")
    @ResponseBody
    public Object login(TUser user) {
        return userDao.findByNameAndPassword(user.getName(), user.getPassword());
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(TUser user) {
        return userDao.save(user);
    }
    @RequestMapping("/update")
    @ResponseBody
    public Object update(TUser tuser){
        tuser.setPassword(tuser.getRepassword());
        tuser.setId(tuser.getId());
        tuser.setName(tuser.getName());
        return userDao.save(tuser);
    }
}
